package com.frxuexi.park2212.patrol

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ItemDecoration
import androidx.recyclerview.widget.RecyclerView.VERTICAL
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.frxuexi.lib_base.base.BaseActivity
import com.frxuexi.lib_base.entity.PointBeanItem
import com.frxuexi.park2212.R
import com.frxuexi.park2212.databinding.ActivityTaskDetailBinding
import dagger.hilt.android.AndroidEntryPoint

@Route(path = "/app/TaskDetailActivity")
@AndroidEntryPoint
class TaskDetailActivity : BaseActivity<ActivityTaskDetailBinding,PatrolViewModel>() {
    @Autowired
    lateinit var tid:String
    val list = mutableListOf<PointBeanItem>()
    val patrolLocationAdapter by lazy { PatrolLocationAdapter() }
    override fun initData() {
        vm.getPointById.observe(this){
            Log.i("===",it.toString())
//            list.add(it)
            patrolLocationAdapter.addData(it)
            patrolLocationAdapter.notifyDataSetChanged()
        }

        vm.getTasksBId.observe(this){
            binding.taskdetailName.setText(it.taskName)
            binding.taskdetailTime.setText(it.patrolTime)
            it.patrolPoints.forEach {
                vm.getPointsById(it)
            }
        }
    }

    override fun initView() {
        ARouter.getInstance().inject(this)
        vm.getTaskById(tid.toInt())

        binding.rvLocation.apply {
            adapter=patrolLocationAdapter
            layoutManager=LinearLayoutManager(this@TaskDetailActivity)
            addItemDecoration(DividerItemDecoration(this@TaskDetailActivity, VERTICAL))
        }
    }
}